/*
 * @Description:
 * @Date: 2023-02-16 17:16:58
 */
import { createRouter, createWebHistory } from 'vue-router'
import { qiankunWindow } from 'vite-plugin-qiankun/dist/helper'

export const constantRoutes = [
  {
    path: '/auth/setting/user',
    name: '机构/用户管理',
    component: () => import('@/views/user')
  },
  {
    path: '/auth/setting/role',
    name: '角色管理',
    component: () => import('@/views/role')
  },
  {
    path: '/auth/setting/lawyer',
    name: '律所/律师管理',
    component: () => import('@/views/lawyer')
  }
]
const router = (parentBase) => {
  /**
   * 区别作为微应用运行和独立运行时的路由base
   * 1. 当作为微应用运行时：路由前缀为 ${parentBase}${packagejson.name}`
   *      - parentBase是从主应用中传过来的参数
   *      - packagejson.name是在package.json文件中定义的固定变量，是为了方便使用和便于区分，这个应该大家都能够理解
   * 2. 独立运行时：路由前缀为/auth-react
   */
  const base = qiankunWindow.__POWERED_BY_QIANKUN__ ? parentBase : '/'
  return createRouter({
    history: createWebHistory(base),
    routes: constantRoutes,
    scrollBehavior(to, from, savedPosition) {
      if (savedPosition) {
        return savedPosition
      } else {
        return { top: 0 }
      }
    }
  })
}

export { router }
